package esercitazione5.JUnitTest;

import org.junit.*;

import static org.junit.Assert.*;
import esercitazione5.graphs.Edge;
import esercitazione5.graphs.Graph;
import esercitazione5.graphs.Vertex;

public class GraphTest {

	private Graph<Integer,Integer> g;
	
	@Before
	public void setUp(){
		g = new Graph<Integer,Integer>();
	}
	
	@Test
	public void testInsertVertex(){
		Vertex<Integer> v  = g.insertVertex(3);
		assertEquals(g.numVertices(), 1);
		assertEquals(v.getValue(), new Integer(3));
	}
	
	@Test
	public void testInsertEdge(){
		Vertex<Integer> s = g.insertVertex(3);
		Vertex<Integer> d = g.insertVertex(6);
		Edge<Integer> e = g.insertEdge(s, d, 1);
		assertEquals(g.numEdges(), 1);
		assertEquals(e.getSource(), s);
		assertEquals(e.getDestination(), d);
		assertEquals(e.getProperty("weight"), 1);
		
	}
	
	@Test
	public void testNumVertices(){
		g.insertVertex(2);
		g.insertVertex(34);
		g.insertVertex(4);
		assertEquals(g.numVertices(), 3);
	}
	
	@Test
	public void testNumEdges(){
		Vertex<Integer> v = g.insertVertex(2);
		Vertex<Integer> s = g.insertVertex(34);
		Vertex<Integer> d = g.insertVertex(4);
		g.insertEdge(s, d, 2);
		g.insertEdge(s, s, 1);
		g.insertEdge(v, d, 3);
		g.insertEdge(s, v, 3);
		assertEquals(g.numEdges(), 4);
	}
	
	@Test
	public void testVerticesList(){
		g.insertVertex(2);
		g.insertVertex(34);
		g.insertVertex(4);
		int i = 0;
		for(Vertex<Integer> v :g.vertices())
			i++;
		assertEquals(i, g.numVertices());
	}
	
	@Test
	public void testEdgesList(){
		Vertex<Integer> v = g.insertVertex(2);
		Vertex<Integer> s = g.insertVertex(34);
		Vertex<Integer> d = g.insertVertex(4);
		g.insertEdge(s, d, 2);
		g.insertEdge(s, s, 1);
		g.insertEdge(v, d, 3);
		g.insertEdge(s, v, 3);
		int i = 0;
		for(Edge<Integer> e : g.edges())
			i++;
		assertEquals(i, g.numEdges());
	}
	
	@Test
	public void testOutgoingEdges(){
		Vertex<Integer> v = g.insertVertex(2);
		Vertex<Integer> s = g.insertVertex(34);
		Vertex<Integer> d = g.insertVertex(4);
		g.insertEdge(s, d, 2);
		g.insertEdge(s, s, 1);
		g.insertEdge(s, v, 3);
		int i = 0;
		for(Edge<Integer> e : g.outgoingEdges(s))
			i++;
		assertEquals(i, 3);
	}
}
